-- buff精确时间
local function ConversionDHMS(time)
    if time > 60 then
        msg = tostring(math.ceil(time / 60)) .. 'm'
    else
        msg = tostring(math.ceil(time)) .. 's'
    end
    return msg
end
local function TuiBuffTimeLoad(buffButton)
    local TuiBuffTime = buffButton:CreateFontString('TuiBuffTime', 'BACKGROUND', 'GameFontNormalSmall')
    TuiBuffTime:SetPoint('TOP', buffButton, 'BOTTOM')
    -- TuiBuffTime:SetVertexColor(255, 255, 255)
    buffButton.timing = TuiBuffTime
end
local function TuiBuffTimeCalculation(buffButton)
    local time = buffButton.timeLeft
    if (time and time > 0) then
        -- buffButton.timing:Show()
        -- buffButton.timing:SetScale(0.7);
        if time > 60 then
            buffButton.timing:SetTextColor(255, 165, 0)
        else
            buffButton.timing:SetTextColor(255, 255, 255)
        end
        buffButton.timing:SetText(ConversionDHMS(time))
    else
        buffButton.timing:Hide()
    end
end

local function TuiBuffTimeUpdate(buffFrame)
    local buffButtons = FunReturnToTable(buffFrame:GetChildren())
    if buffButtons then
        for _, buffButton in pairs(buffButtons) do
            if TuiDB.IsBuffTime then
                if buffButton.duration:IsVisible() then
                    buffButton.duration:SetShown(false)
                end
                if buffButton.timing then
                    if buffButton.timing:IsVisible() == false then
                        buffButton.timing:SetShown(true)
                    end
                    TuiBuffTimeCalculation(buffButton)
                else
                    TuiBuffTimeLoad(buffButton)
                end
            else
                if buffButton.duration:IsVisible() == false then
                    buffButton.duration:SetShown(true)
                end
                if buffButton.timing and buffButton.timing:IsVisible() then
                    buffButton.timing:SetShown(false)
                end
            end

        end
    end
end
TuiBuffTime = CreateFrame('Frame')
TuiBuffTime.Events = {
    ['ADDON_LOADED'] = function(self)
        self:UnregisterEvent('ADDON_LOADED')
        local BuffFrame = _G['BuffFrame']
        BuffFrame:HookScript('OnUpdate', TuiBuffTimeUpdate)
    end

}
